<?php
namespace Admin\Controller;

class IndexController extends ComController
{
    public function index()
    {
        $info = array();

        //今日新增会员,会员总数
        $starttime = date('Y-m-d 00:00:00');
        $endtime = date('Y-m-d 23:59:59');
        $mcStarttime = strtotime($starttimet);
        $mcEndtime = strtotime($endtime);

        $userModel = M('Users');
        $info['userTotal'] = $userModel->where(['status'=>1])->count();

        $map = array(
            'createtime' => array('gt'=>$starttime, 'lt'=> $endtime)
        );

        $info['userNumToday'] = $userModel->where($map)->count();

        //打卡统计
        $where = array(
            'businessId'=>'10101',
            'createTime' => array(['lt',$endtime],['gt',$starttime]),
        );

        $info['signTotal'] = intval(M('Score_tran')->where($where)->group('uid')->count());

        //卡券消费
        $where = array(
            'usetime' => array(['lt',$mcEndtime],['gt',$mcStarttime])
        );

        $info['cardConsume'] = intval(M('Vip_card')->where($where)->sum('money'));

        $this->assign('info', $info);

        $model    = new \Think\Model();
        // $mysql = $model->query("select VERSION() as mysql");
        $p        = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $t        = time() - 3600 * 24 * 60;
        $log      = M('log');

        $log->where("t < $t")->delete();//删除60天前的日志

        $pagesize = 15;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $count  = $log->count();
        $list   = $log->order('id desc')->limit($offset . ',' . $pagesize)->select();
        $page   = new \Think\Page($count, $pagesize);
        $page   = $page->show();

        $this->assign('list', $list);
        $this->assign('page', $page);

        // $this->assign('mysql', $mysql[0]['mysql']);
        // $this->assign('nav', array('', '', ''));//导航

        //新增会员
        $this->display();
    }
}
